import {defineConfig, loadEnv} from "vite";
import path from "path";
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'

import vwt from 'weapp-tailwindcss-webpack-plugin/vite';


const postcssPlugins = [require('autoprefixer')(), require('tailwindcss')()];
postcssPlugins.push(
  require('postcss-rem-to-responsive-pixel')({
    rootValue: 32,
    propList: ['*'],
    transformUnit: 'rpx',
  })
);

export default defineConfig(({mode, command}) => {
  const env = loadEnv(mode, process.cwd());
  // const {VITE_APP_ENV} = env;
  return {
    define: {
      'process.env': env,
    },
    resolve:{
      alias: {
        '@': path.resolve(__dirname , "./src"),
      },
      extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
    },

    plugins: [
      uni(),
      vwt(),
      AutoImport({
        include: [/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
          /\.vue$/, /\.vue\?vue/, // .vue
          /\.md$/, // .md
        ],
        imports: [
          'vue',
          'pinia',
        ],
        resolvers: [],
        dts: true,
      }),
      Components({
        dirs: [],
        dts: true,
      }),

    ],
    css: {
      postcss: {
        plugins: postcssPlugins,
      },
    },
  }
})
